package com.jiaquyun.jcyx.main.goods

import android.app.Activity
import android.content.Intent
import com.jiaquyun.jcyx.R
import com.jiaquyun.jcyx.entity.Cat
import com.jiaquyun.jcyx.jetpack.mode.GoodsViewModel
import com.module.lemlin.owner.OwnerViewModeActivity
import kotlinx.android.synthetic.main.activity_goods_screen.*

class GoodsScreenActivity : OwnerViewModeActivity<GoodsViewModel>() {

    companion object {
        private const val KEY_NAME_CATE = "KEY_NAME_CATE"
        fun open(activity: Activity, cateEntity: Cat? = null) {
            val intent = Intent(activity, GoodsScreenActivity::class.java)
            intent.putExtra(KEY_NAME_CATE, cateEntity)
            activity.startActivity(intent)
        }
    }

    override val layoutResId: Int
        get() = R.layout.activity_goods_screen

    override fun viewModel(): GoodsViewModel {
        return createViewModel()
    }

    override fun stateBar(): StatusBar {
        return StatusBar(color = R.color.colorWhite, view = flGoodsScreenBar)
    }

    override fun initView() {

        ivAppBack.setOnClickListener { finish() }
        val cateEntity: Cat = intent?.getSerializableExtra(KEY_NAME_CATE) as? Cat
            ?: return

        setSupportFragmentManager(cateEntity)

        tvGoodsScreenTitle.text = cateEntity.name

    }

    override fun initData() {

    }


    private fun setSupportFragmentManager(cateEntity: Cat?) {
        supportFragmentManager.beginTransaction().apply {
            replace(R.id.flGoodsScreenBody, GoodsScreenFragment.newInstance(cateEntity))
        }.commit()
    }

}